import 'package:flutter/material.dart';
import 'package:intl/intl.dart';

class DateTimePage extends StatefulWidget {
  final Map<String, dynamic> arguments;
  DateTimePage({Key key, this.arguments}) : super(key: key);

  @override
  _DateTimePageState createState() => _DateTimePageState();
}

class _DateTimePageState extends State<DateTimePage> {
  DateTime selectedDate = DateTime.now();
  TimeOfDay selectedTime = TimeOfDay.now();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('DateTimePage'),
      ),
      body: ListView(
        children: <Widget>[
          ListTile(
            title: Row(
              children: <Widget>[
                Text('showDatePicker: ' + DateFormat.yMMMd().format(this.selectedDate)),
                Icon(Icons.arrow_drop_down),
              ],
            ),
            onTap: () {
              this._selectDate();
            },
          ),
          Divider(height: 1.0),
          ListTile(
            title: Row(
              children: <Widget>[
                Text('showTimePicker: ' + this.selectedTime.format(context)),
                Icon(Icons.arrow_drop_down),
              ],
            ),
            onTap: () {
              this._selectTime();
            },
          ),
          Divider(height: 1.0),
        ],
      ),
    );
  }

  _selectDate() async {
    final DateTime date = await showDatePicker(
      context: context,
      initialDate: selectedDate,
      firstDate: DateTime(1900),
      lastDate: DateTime(2100),
    );

    if (date == null) return;

    setState(() {
      this.selectedDate = date;
    });
  }

  _selectTime() async {
    final TimeOfDay time = await showTimePicker(
      context: context,
      initialTime: this.selectedTime,
    );

    if (time == null) return;

    setState(() {
      this.selectedTime = time;
    });
  }
}
